package com.example.black.myapplication.mynet;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import com.example.black.myapplication.R;

import java.io.UnsupportedEncodingException;

public class WeatherActivity extends AppCompatActivity {

   // public static final String URL = "http://api.yytianqi.com/observe?city=123.113.202.176&key=j5l6tlswucvuk0mi";
    public static final String URL = "http://ap.yytianqi.com/observe?city=123.113.202.176&key=j5l6lswucvuk0mi";
    private TextView textView;
    String string = "test";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_weather);
        initView();
    }

    private void initView() {
        textView = findViewById(R.id.textView);
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    new MyOKHttp<String>().sendData(
                            URL
                            , string.getBytes("utf-8")
                            , new IJSONResponseCallBack<String>() {
                                @Override
                                public void onSuccess(String data) {
                                    textView.setText(data);
                                }

                                @Override
                                public void onFailure(Throwable throwable) {
                                    textView.setText(throwable.getMessage());
                                }
                            },String.class
                    );
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            }
        });
    }
}
